import os
import shutil
import compileall

endDir = "./../buildserver/"
dirList = ['bill','manager','center','gate','login','game','pycommon','remotelog','shell']

def get_File_path(rootdir):
    dirs = [];
    for parent,dirnames,filenames in os.walk(rootdir):
        #for dirname in  dirnames:
        #    print "parent is:" + parent;
        #    print  "dirname is:" + dirname;
        #    dirs.append(dirname);
        for filename in filenames:
            if os.path.splitext(filename)[1] == ".py":
                filePath = os.path.join(parent,filename);
                dirs.append(filePath.replace("\\","/"));
    return dirs;

def main():
    print("#######################build start#######################")
    exit = os.path.exists(endDir)
    if exit:
        shutil.rmtree(endDir)
    os.mkdir(endDir)
    for dir in dirList:
        shutil.copytree(dir,endDir + dir)
        compileall.compile_dir(endDir + dir)
    files = get_File_path(endDir);
    for file in files:
        os.remove(file)
    print("#######################build end#######################")
    raw_input()
    

if __name__ == '__main__':
    main()